﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="dclist.aspx.cs" Inherits="CSWeb.easyui_test.dclist" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="dg"></div>

    <script type="text/javascript">

        $(function () {
            <% string[] cnames = new string[] { "语文", "数学", "英语" }; %>
            var arrCNames = ["语文", "数学", "英语"];
            //列表
            var dg = $('#dg').datagrid({
                url: '/service/Mysoft.Test.Services.DL/List.aspx',
                fit: false,
                frozenColumns: [[
                    { field: 'UserName', title: '用户名', width: 150 },
                    {
                        field: 'TotalScore', title: '总分', width: 150,
                        settings: function (v, d, i) {
                            return JSON.stringify({
                                formula: "D{0}+E{0}+F{0}".replace(/\{0\}/g, parseInt(i) + 2)
                            });
                        },
                        editor: {
                            type: 'textbox',
                            options: {
                                editable: false
                            }
                        }
                    }
                ]],
                columns: [[
                    <% foreach (string nm in cnames)
                       {
                    %>
                    {
                        field: '<%=nm %>', title: '<%=nm %>', width: 150,
                        editor: {
                            type: 'textbox',
                            options: {
                                onChange: function (nval) {
                                    var index = dg.datagrid('editingRowIndex', this);
                                    var edTotal = dg.datagrid('getEditor', { index: index, field: "TotalScore" });
                                    var sum = 0;
                                    for (var i = 0; i < arrCNames.length; i++) {
                                        var ed = dg.datagrid('getEditor', { index: index, field: arrCNames[i] });
                                        sum += parseFloat($(ed.target).textbox('getValue'));
                                    } 
                                    $(edTotal.target).textbox('setValue', sum);
                                }
                            }
                        }
                    },
                    <% 
                       } 
                    %>
                ]],
                onClickRow: function (index, row) {
                    dg.datagrid('beginEdit', index);
                },
                toolbar: []
            });
        });

    </script>
</asp:Content>
